<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.List" %>
<%@ page import="oneroom.comm.BaseUtil" %>
<%@ page import="oneroom.admin.board.boardModel" %>
<%@ page import="oneroom.admin.code.codeModel" %>
<jsp:useBean id="dao" scope="page" class="oneroom.admin.board.boardDao" />
<jsp:useBean id="codeDao" scope="page" class="oneroom.admin.code.codeDao" />
<%
	String redirectUrl = "";
	if (session.getAttribute("id") != null &&
			((String)session.getAttribute("id")).equals("") == false) {
	} else {
		redirectUrl = "/room/member/login.jsp";
		response.sendRedirect(redirectUrl);
	}

	List codeList = codeDao.getDtlList("200");
	/*
	페이징 관련 
	*/
	String pageName = "list.jsp";
	String viewName = "view.jsp";
	int     giSelectPage  	= Integer.parseInt(request.getParameter("txtSelectPage") == null ? "0" :request.getParameter("txtSelectPage"));			//현재 선택된 페이지 저장
	int     giSelectBlock 	= Integer.parseInt(request.getParameter("txtSelectBlock") == null ? "0" :request.getParameter("txtSelectBlock"));			//현재 선택된 블락페이지 저장
	String searchGubn  = request.getParameter("searchGubn") == null ? "" : request.getParameter("searchGubn");
	String searchValue = request.getParameter("searchValue") == null ? "" : request.getParameter("searchValue");
	String searchBoard = request.getParameter("searchBoard") == null ? "1" : request.getParameter("searchBoard");
	int     giCount       	= 0;			//리스트 for문 break문에 사용
	int     giRecordcnt   	= 0;			//리스트의 카운터에 사용
	int     giPageSize    	= 10;  			// 한페이지에 나타내고자 하는 List수
	int     giBlockSize   	= 10;   		// Block의 수
	int     giCurPage     	= 1;   			// 현재 Page
	int     giCurBlock    	= 0;   			// 현재 Block
	int     giStartPos    	= 0;   			// 시작 List 위치
	int     giTotPage     	= 0;   			// 총 Page수
	int     giTotBlock    	= 0;   			// 총 Block수
	//  넘겨온 값 받기(List페이지 관련)...
	if ( giSelectPage  >  0 ) { 			// 선택된 Page값이 있을경우....     
		giCurPage  = giSelectPage;   	// 현재Page = 선택된Page 
		giCurBlock = giSelectBlock;  	// 블락page = 선택된 블락 page
	}
	//쿼리를 돌려서 가지고 오는 값
	List list = dao.getList(searchBoard,searchGubn,searchValue, giSelectPage, giPageSize);
	if (list.size() > 0 ) {
		//전체 게시물 수
		giRecordcnt = dao.getCount(searchBoard,searchGubn,searchValue); 			// 총 list 수
	}
	if (giRecordcnt > 0) {  // 조건에 맞는 값이 있으면....
		giTotPage  = giRecordcnt / giPageSize;
		if (giRecordcnt % giPageSize != 0) {
			giTotPage = giTotPage + 1;			// 총 Page수를 구한다...
		}
		giTotBlock = giTotPage / giBlockSize;
		if (giTotPage % giBlockSize != 0) {
			giTotBlock = giTotBlock + 1;		// 총 Block수를 구한다...
		}
	}

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>원룸몬스터</title>

<link href="/room/css/all.css" rel="stylesheet" type="text/css" />
<script src="/room/script/swfobject_modified.js" type="text/javascript"></script>
<script src="/room/script/common.js" type="text/javascript"></script>
<script src="/room/script/jquery-1.3.2.min.js" type="text/javascript" ></script>
<script type="text/javascript">
<!--
$(document).ready(function(){
	$('#wrtBtn').click(function() {
		window.location.href="write.jsp?searchBoard=<%=searchBoard%>";
	});
});

function goView(data_id){
	document.frmView.data_id.value = data_id;
	document.frmView.submit();
}

//-->
</script>
</head>

<body>
<div align="center"> 

 <div id="content">

<!----------------왼쪽---------------->  
<%@ include file="/room/common/left.jsp" %>
<!----------------왼쪽끝---------------->  


<!----------------가운데 시작----------------> 
 <div id="rgt">
  <div id="con01">
   <div class="top bb1"><img src="/room/img/txt_top.gif" /></div>

<div class="list h550">
 <div class="pb10"><img src="/room/img/line_blue.gif" width="32" height="2" /></div>
       <div class="tit">게시판 </div>
<!------------------검색박스 시작---------------------->
<form action="list.jsp" name="frm" id="frm" method="post">
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td style="padding-left:10px;">
   		<select name="searchGubn" style="width:80px;">
			<option value="all" <%if(searchGubn.equals("all")){out.print(" selected='selected'");} %>>전체</option>
			<option value="title" <%if(searchGubn.equals("title")){out.print(" selected='selected'");} %>>제목</option>
			<option value="content" <%if(searchGubn.equals("content")){out.print(" selected='selected'");} %>>내용</option>
		</select>
		<input type="text" name="searchValue" style="width:120px;" value="<%=searchValue %>" />
		
	</td>
    <td style="padding-left:10px;">
	  <a class="d" href="#" onclick="document.frm.submit();"><div class="btn_b47">검색</div></a>
	</td>
  </tr>
</table>	
</form>
<!----------------검색박스 끝---------------->
<table width="595" border="0" cellspacing="0" cellpadding="0">
<col width="8%" />
<col width="52%" />
<col width="15%" />
<col width="15%" />
<col width="10%" />
  <tr>
    <td class="ac fw bt2 bb1 h30 bg_g">번호</td>
    <td class="ac fw bt2 bb1 h30 bg_g">제목</td>
    <td class="ac fw bt2 bb1 h30 bg_g">ID</td>
    <td class="ac fw bt2 bb1 h30 bg_g">날짜</td>
    <td class="ac fw bt2 bb1 h30 bg_g">조회수</td>
  </tr>
	<%
		if(list != null && list.size() > 0){
			giCount  = 1;
			giRecordcnt = giRecordcnt - ( giCurPage -1 ) * giPageSize;	
			giStartPos = ((giCurPage - 1) * giPageSize) + 1;
			for(int i = 0; i<list.size(); i++){
				boardModel model = (boardModel)list.get(i);
	%>  
	<tr>
		<td class="ac bb1 h30"><%=giRecordcnt %></td>
		<td class="fw bb1 h30"><a class="c" href="javascript:goView('<%=model.getData_id() %>')">
		<%for(int j=0;j<model.getDeth();j++){%><img src="/room/img/icon_reply.gif" /> <%} %>
		<%=model.getTitle() %></a>
		<% if(BaseUtil.betweenDate(BaseUtil.getCurrentTime("yyyyMMdd"),model.getReg_date().replace(".","")) == 0){ %>
		<img src="/room/img/icon_new.gif" />
		<%} %>
		</td>
		<td class="ac bb1 h30"><%=model.getReg_id() %></td>
		<td class="ac bb1 h30"><%=model.getReg_date() %></td>
		<td class="ac bb1 h30"><%=model.getHit_count() %></td>
		
	</tr>
	<%
				giCount = giCount + 1;
				giRecordcnt = giRecordcnt - 1;
			}
		}else{
	%>
	<tr><td class="ac bb1 h30" colspan="5">등록된 내용이 없습니다.</td></tr>
	<%
		}
	%>
</table>
   <div class="pt15">
    <table width="595" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>
	<%@ include file="/room/common/pages.jsp" %>
     </td>
  <%if(!searchBoard.equals("1")){ %>     
    <td width="50" align="right"><a class="d" href="#" id="wrtBtn"><div class="btn_b47">등록</div></a></td>
  <%} %>    
  </tr>
</table>
</div>
</div>
</div>  
<form action="view.jsp" method="post" name="frmView" >
<input type="hidden" name="searchGubn" value="<%=searchGubn %>"/>
<input type="hidden" name="searchValue" value="<%=searchValue %>"/>
<input type="hidden" name="txtSelectPage" value="<%=giSelectPage %>"/>
<input type="hidden" name="txtSelectBlock" value="<%=giSelectBlock %>"/>
<input type="hidden" name="searchBoard" value="<%=searchBoard %>"/>
<input type="hidden" name="data_id" value=""/>
</form>
<!----------------오른쪽 시작---------------->  
<%@ include file="/room/common/right.jsp" %>  
<!----------------오른쪽 끝---------------->
</div>


<!-------------푸터영역----------> 
<%@ include file="/room/common/footer.jsp" %> 
<!-------------푸터영역----------> 
<script type="text/javascript">
swfobject.registerObject("FlashID");
</script>
</body>
</html>
